package com.example.demo.utils;

import java.util.Random;
import java.util.UUID;

/**
 * @author xieluoyin
 */
public class KeyUtil {

    private KeyUtil() {

    }

    /**
     * 生成唯一的主键
     * 格式: 时间+随机数
     *
     * @return 主键
     */
    public static synchronized String genUniqueKey() {
        Random random = new Random();
        //生成六位随机数
        //Integer number = random.nextInt(900000) + 100000;
        Integer number = random.nextInt(900) + 100;

        return System.currentTimeMillis() + String.valueOf(number);
    }

    public static String gen32UUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
}
